package com.robot.log.controller;

import com.alibaba.fastjson.JSON;
import com.robot.log.pojo.SearchLog;
import com.robot.log.service.SearchLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * searchLog控制器层
 *
 * @author wuyunbin
 */
@RestController
@CrossOrigin
@RequestMapping("/searchLog")
public class SearchLogJsonController {
    @Autowired
    private SearchLogService searchLogService;

    /**
     * 根据memberId和keywords查找搜索记录,同一用户搜索相同关键词只记录一次
     *
     * @param memberId
     * @param keywords
     * @return
     */
    @GetMapping(value = "third/findSearchLogByMemberIdAndKeywords/{memberId}/{keywords}", produces = "application/json;charset=utf-8")
    public String thirdFindSearchLogByMemberIdAndKeywords(@PathVariable String memberId, @PathVariable String keywords) {
        return JSON.toJSONString(searchLogService.findByMemberIdAndKeywords(memberId, keywords));
    }

    /**
     * 增加搜索
     *
     * @param searchLog
     * @return
     */
    @PostMapping(value = "third/addSearchLog", produces = "application/json;charset=utf-8")
    public void thirdAddSearchLog(@RequestBody String searchLog) {
        searchLogService.add(JSON.parseObject(searchLog, SearchLog.class));
    }
}
